package com.yihusitian.zsxq.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yihusitian.zsxq.pojo.data.UserDO;
import com.yihusitian.zsxq.pojo.dto.Like;
import com.yihusitian.zsxq.service.IDGenerator;
import com.yihusitian.zsxq.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yihusitian.zsxq.pojo.data.LikeDO;
import com.yihusitian.zsxq.service.LikeService;
import com.yihusitian.zsxq.mapper.LikeMapper;

import java.util.List;

/**
 * @Description TODO
 * @Author LeeHo
 * @Date 2021-03-25 16:32:44
 */
@Service
public class LikeServiceImpl extends ServiceImpl<LikeMapper, LikeDO> implements LikeService {

    @Autowired
    private UserService userService;

    @Override
    public void createLikes(List<Like> latestLikes, Long topicId) {
        if (CollectionUtil.isNotEmpty(latestLikes)) {
            latestLikes.forEach(like -> {
                UserDO userDO = userService.createOrUpdate(like.getOwner());
                LikeDO.builder().id(IDGenerator.generateId()).ownerId(userDO.getId()).topicId(topicId).createTime(like.getCreateTime()).build().insert();
            });
        }
    }
}